package com.gamelife.web.controller.system;


import com.gamelife.web.domain.AjaxResult;
import com.gamelife.web.domain.entity.SysUser;
import com.gamelife.web.domain.modle.UserParam;
import com.gamelife.web.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hsx
 * @since 2022-06-27
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/sys/user")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    @GetMapping("list")
    @ApiOperation("获取用户列表")
    @PreAuthorize("hasAuthority('sys:user:list')")
    public AjaxResult list(UserParam userParam){
        List<SysUser> sysUserList = sysUserService
                .selectList(userParam.getUsername(), userParam.getPageNum(), userParam.getPageSize());
        return AjaxResult.success(sysUserList);
    }

    @PostMapping("save")
    @ApiOperation("添加用户")
    @PreAuthorize("hasAuthority('sys:user:save')")
    public AjaxResult save(@RequestBody SysUser sysUser){
        return AjaxResult.success(sysUserService.insertSysUser(sysUser));
    }

    @PutMapping("update")
    @ApiOperation("修改用户信息")
    @PreAuthorize("hasAuthority('sys:user:update')")
    public AjaxResult update(
            @ApiParam("通过修改state实现账号状态管理,0正常、1停用、2逻辑删除")
            @RequestBody SysUser sysUser){
        return AjaxResult.success(sysUserService.updateSysUser(sysUser));
    }
}
